﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using CrystalDecisions.CrystalReports.Engine;

using BLL;
using DAL;
using Models;
using System.Data;
using System.Text;
using System.Xml;
using Web.Old_App_Code;

public partial class backstage_recruitment : System.Web.UI.Page
{
    // Fields


    protected Recruitment rt = new Recruitment();
    protected RecruitmentManager rtm = new RecruitmentManager();


    // Methods
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        string pathAndQuery = HttpContext.Current.Request.Url.PathAndQuery;
        try
        {
            this.rt.JobTitle = this.txtJobTitle.Value;
            this.rt.WorkAddress = this.txtWorkAddress.Value;
            this.rt.RecruitmentCount = Convert.ToInt32(this.txtRecruitmentCount.Value);
            this.rt.StartDate = Convert.ToDateTime(this.txtStartDate.Value);
            this.rt.EndDate = Convert.ToDateTime(this.txtEndDate.Value);
            this.rt.Skill = this.fckSkill.Value;
            this.rt.IsShow = Convert.ToInt32(base.Request.Form["isShow"]);
            if ((base.Request.QueryString["ot"] == "ed") && (base.Request.QueryString["id"] != null))
            {
                this.rt.Id = Convert.ToInt32(base.Request.QueryString["id"]);
                if (this.rtm.ModifyRecruitment(this.rt))
                {
                    base.ClientScript.RegisterStartupScript(base.GetType(), "message", "<script language=\"javascript\" defer>alert(\"更新成功！\");location.href=\"recruitment_list.aspx\";</script>");
                }
                else
                {
                    base.ClientScript.RegisterStartupScript(base.GetType(), "message", "<script language=\"javascript\" defer>alert(\"更新失败！\");</script>");
                }
            }
            else
            {
                this.rt.LanguageVersion = this.Session["language_version"].ToString();
                if (this.rtm.AddRecruitment(this.rt))
                {
                    base.ClientScript.RegisterStartupScript(base.GetType(), "message", "<script language=\"javascript\" defer>alert(\"添加成功！\");location.href=\"recruitment_list.aspx\";</script>");
                }
                else
                {
                    base.ClientScript.RegisterStartupScript(base.GetType(), "message", "<script language=\"javascript\" defer>alert(\"添加失败！\");</script>");
                }
            }
        }
        catch
        {
            if ((base.Request.QueryString["ot"] == "ed") && (base.Request.QueryString["id"] != null))
            {
                base.ClientScript.RegisterStartupScript(base.GetType(), "message", "<script language=\"javascript\" defer>alert(\"更新失败！\");</script>");
            }
            else
            {
                base.ClientScript.RegisterStartupScript(base.GetType(), "message", "<script language=\"javascript\" defer>alert(\"添加失败！\");</script>");
            }
        }
    }

    public StringBuilder GetTitle()
    {
        StringBuilder builder = new StringBuilder();
        try
        {
            if (base.Request.QueryString["ot"] == null)
            {
                return builder;
            }
            if ((base.Request.QueryString["ot"] == "ed") && (base.Request.QueryString["id"] != null))
            {
                builder.Append("编辑职位");
                return builder;
            }
            builder.Append("添加职位");
        }
        catch
        {
        }
        return builder;
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if ((HttpContext.Current.Session["admin_user"] == null) && (HttpContext.Current.Session["language_version"] == null))
        {
            base.ClientScript.RegisterStartupScript(base.GetType(), "sJs", "top.location=\"login.html\";", true);
        }
        if (!base.IsPostBack && (base.Request.QueryString["ot"] != null))
        {
            if ((base.Request.QueryString["ot"] == "ed") && (base.Request.QueryString["id"] != null))
            {
                this.RecruitmentBind();
            }
            else
            {
                this.txtRecruitmentCount.Value = "0";
                this.rdIsShow1.Checked = true;
            }
        }
    }

    private void RecruitmentBind()
    {
        try
        {
            DataTable recruitmentById = this.rtm.GetRecruitmentById(Convert.ToInt32(base.Request.QueryString["id"]));
            if (recruitmentById.Rows.Count > 0)
            {
                this.txtJobTitle.Value = recruitmentById.Rows[0]["jobTitle"].ToString();
                this.txtWorkAddress.Value = recruitmentById.Rows[0]["workAddress"].ToString();
                this.txtRecruitmentCount.Value = recruitmentById.Rows[0]["recruitmentCount"].ToString();
                this.txtStartDate.Value = recruitmentById.Rows[0]["startDate"].ToString();
                this.txtEndDate.Value = recruitmentById.Rows[0]["endDate"].ToString();
                this.fckSkill.Value = recruitmentById.Rows[0]["skill"].ToString();
                if (Convert.ToInt32(recruitmentById.Rows[0]["isShow"]) == 1)
                {
                    this.rdIsShow1.Checked = true;
                }
                else
                {
                    this.rdIsShow0.Checked = true;
                }
            }
        }
        catch
        {
        }
    }

}